package JUnit;

import java.sql.Date;

import DataBase.IDAOImpl.i_Note_Impl;
import Protocal.Note.Note;
import junit.framework.TestCase;

public class i_Note_ImplTest extends TestCase {

	protected void setUp() throws Exception {		
		super.setUp();
		i_Note_Impl in = new i_Note_Impl();
		Note note = new Note();
		note.setAuthorid("091250080");
		note.setTime(Date.valueOf("2011-3-4"));
		note.setContent("Note test1");
		note.setUpdatetime(Date.valueOf("2011-3-8"));
		in.addNote(note);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		i_Note_Impl in = new i_Note_Impl();
		in.deleteByTime("091250080", Date.valueOf("2011-3-4"));
	}

	public void testAddNote() {
		i_Note_Impl in = new i_Note_Impl();
		Note note = new Note();
		note.setAuthorid("091250013");
		note.setTime(Date.valueOf("2011-3-4"));
		note.setContent("AddNote Test");
		note.setUpdatetime(Date.valueOf("2011-3-4"));
		in.addNote(note);
		
		Note rs = in.getNoteByTime("091250013", Date.valueOf("2011-3-4"));
		assertTrue(rs.getAuthorid().equals("091250013") && rs.getTime().equals(Date.valueOf("2011-3-4")));
		in.deleteByTime("091250013", Date.valueOf("2011-3-4"));
		//fail("Not yet implemented");
	}

	public void testDeleteByTime() {
		i_Note_Impl in = new i_Note_Impl();
		in.deleteByTime("091250080", Date.valueOf("2011-3-4"));
		Note rs = in.getNoteByTime("091250080", Date.valueOf("2011-3-4"));
		assertNull(rs);
		
		//("Not yet implemented");
	}

	public void testGetNoteByTime() {
		i_Note_Impl in = new i_Note_Impl();
		Note note = new Note();
		note.setAuthorid("091250009");
		note.setTime(Date.valueOf("2011-3-4"));
		note.setContent("GetNote Test");
		note.setUpdatetime(Date.valueOf("2011-3-8"));
		in.addNote(note);
		
		Note rs = in.getNoteByTime(note.getAuthorid(), note.getTime());
		assertTrue(rs.getAuthorid().equals(note.getAuthorid()) && rs.getTime().equals(note.getTime()));
		in.deleteByTime(note.getAuthorid(), note.getTime());
		
		//fail("Not yet implemented");
	}

	public void testUpdateNote() {
		i_Note_Impl in = new i_Note_Impl();
		Note note = new Note();
		note.setAuthorid("091250009");
		note.setTime(Date.valueOf("2011-3-6"));
		note.setContent("Upadate Test");
		note.setUpdatetime(Date.valueOf("2011-3-8"));
		in.addNote(note);
		
		note.setContent("Update Test New");
		in.updateNote(note);
		
		Note rs = in.getNoteByTime(note.getAuthorid(), note.getTime());
		assertTrue(rs.getContent().equals("Update Test New"));
		in.deleteByTime(note.getAuthorid(), note.getTime());
		//fail("Not yet implemented");
		
	}

}
